﻿using Communergy.Common.Comparers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Communergy.Common;
using System.Collections.Generic;
using System.Linq;

namespace Communergy.Common.Tests
{
    
    
    /// <summary>
    ///This is a test class for EnergyDataComparerTest and is intended
    ///to contain all EnergyDataComparerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class EnergyDataComparerTest
    {



        /// <summary>
        ///A test for Equals
        ///</summary>
        [TestMethod()]
        public void EnergyDataComparer_CompareEqualDateAndIntervalDifferentWatts_WillBeTrue()
        {
            EnergyDataComparer target = new EnergyDataComparer(); // TODO: Initialize to an appropriate value

            DateTime dateTime = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 0, 6);

            EnergyData x = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 100M };
            EnergyData y = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 200M };            
            var isEqual = target.Equals(x, y);
            Assert.IsTrue(isEqual);
        }


        [TestMethod()]
        public void EnergyDataComparer_CompareEqualDateAndIntervalDifferentWattsWithExcept_WillBe0Records()
        {
            EnergyDataComparer comparer = new EnergyDataComparer(); // TODO: Initialize to an appropriate value

            DateTime dateTime = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 0, 6);

            EnergyData x = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 100M };
            List<EnergyData> firstList = new List<EnergyData>{x};
 
            EnergyData y = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 200M };
            List<EnergyData> secondList = new List<EnergyData>{y};

            var differentRecords = firstList.Except(secondList, comparer).ToList();

            Assert.AreEqual(0, differentRecords.Count);
            
        }



        [TestMethod()]
        public void EnergyDataComparer_DifferentDatesEqualInterval_WillBeFalse()
        {
            EnergyDataComparer target = new EnergyDataComparer(); // TODO: Initialize to an appropriate value

            DateTime dateTime = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 0, 6);

            EnergyData x = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 100M };
            EnergyData y = new EnergyData { ReadingDateTime = dateTime.AddDays(1), Interval = interval, AverageWatts = 200M };
            var isEqual = target.Equals(x, y);
            Assert.IsFalse(isEqual);
        }

        [TestMethod()]
        public void EnergyDataComparer_EqualDateDifferentInterval_WillBeFalse()
        {
            EnergyDataComparer target = new EnergyDataComparer(); // TODO: Initialize to an appropriate value

            DateTime dateTime = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 0, 6);
            TimeSpan interval2 = new TimeSpan(0, 0, 12);

            EnergyData x = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 100M };
            EnergyData y = new EnergyData { ReadingDateTime = dateTime, Interval = interval2, AverageWatts = 200M };
            var isEqual = target.Equals(x, y);
            Assert.IsFalse(isEqual);
        }

        [TestMethod()]
        public void EnergyDataComparer_DifferentDateDifferentInterval_WillBeFalse()
        {
            EnergyDataComparer target = new EnergyDataComparer(); // TODO: Initialize to an appropriate value

            DateTime dateTime = DateTime.Now;
            DateTime dateTime2 = DateTime.Now;
            TimeSpan interval = new TimeSpan(0, 0, 6);
            TimeSpan interval2 = new TimeSpan(0, 0, 12);

            EnergyData x = new EnergyData { ReadingDateTime = dateTime, Interval = interval, AverageWatts = 100M };
            EnergyData y = new EnergyData { ReadingDateTime = dateTime2, Interval = interval2, AverageWatts = 200M };
            var isEqual = target.Equals(x, y);
            Assert.IsFalse(isEqual);
        }
        
    }
}
